home *** CD-ROM | disk | FTP | other *** search
/ SGI Enlighten DSM 1.1 / SGI EnlightenDSM 1.1.iso / aix41 / install.z / install / bin / start_enl_daemons < prev    next >
Text File  |  1998-06-30  |  10KB  |  449 lines

  1. #!/bin/sh
  2. #
  3. # Script: start_enl_daemons [-continue] [-restart]
  4. #
  5. # Without given the -continue option, start_enl_daemons
  6. # will exit if any component fails to come up. 
  7. #
  8. # If passed with the "-restart" option, start_enl_daemons
  9. # will "bounce" all currently running daemons
  10. # (i.e. kill them, then restart them).
  11. #
  12. # Without given the -restart option, start_enl_daemons will
  13. # not start any daemon that is already running.
  14. # start_enl_daemons invokes all Enlighten daemons 
  15. # (emd, pep, renld, and Events)
  16. #
  17. # Copyright (c) 1990-1998 Enlighten Software Solutions, Inc.
  18. # All Rights Reserved.
  19. #
  20.  
  21. STARTUP_SECS=5
  22. SHUTDOWN_SECS=10
  23. SMUX_CLEARING_SECS=60
  24. DEFAULT_LOG_LEVEL=0
  25. LOGMIN=0
  26. LOGMAX=4
  27.  
  28. PATH=/bin:/usr/bin:/usr/sbin:/etc:/usr/ucb:/usr/bsd:/usr/etc:$PATH
  29. export PATH
  30.  
  31. appName=`basename $0`
  32.  
  33. hostname=`uname -n`
  34. OS=`uname -s`
  35. REV=`uname -r`
  36. enhancedLicense=
  37. agentmon_option=""
  38.  
  39. #
  40. # Deal with bsd ps
  41. #
  42.  
  43. OPTS="-e"
  44. PIDCOLUMN=1
  45. if [ "$OS" = "SunOS" ]; then
  46.     case "$REV" in
  47.         4.1.* )
  48.             OPTS="-gxww" ; export OPTS
  49.             PIDCOLUMN=1 ; export PIDCOLUMN
  50.             ;;
  51.     esac
  52. fi
  53.  
  54. logLevel=$DEFAULT_LOG_LEVEL
  55.  
  56. while [ "$#" -ne 0 ] ; do
  57.     case "$1" in
  58.         -c* ) 
  59.             CONTINUE=true 
  60.             ;;
  61.         -r* )
  62.             RESTART=true 
  63.             ;;
  64.         -v )
  65.             logLevel=$2
  66.             if [ -z "$logLevel" ] ; then
  67.                 logLevel=$DEFAULT_LOG_LEVEL
  68.                 echo "$appName: Log level was missing."
  69.             else
  70.                 shift
  71.             fi
  72.             ;;
  73.         -v* )
  74.             logLevel=`expr "$1" : '-v\([0-9]*\)'`
  75.             if [ -z "$logLevel" ] ; then
  76.                 logLevel=$DEFAULT_LOG_LEVEL
  77.                 echo "$appName: '$1' is not valid."
  78.             fi
  79.             ;;
  80.         *)
  81.             echo
  82.             echo "$appName is used to invoke all Enlighten daemons."
  83.             echo
  84.             echo "Usage: $appName [-continue] [-restart] [-v <verbosity level (0-4)>]"
  85.             echo "       -continue: ignore any start-up errors and invoke all necessary daemons."
  86.             echo "       -restart:  kill old Enlighten daemons before startup."
  87.             echo
  88.             exit 1
  89.             ;;
  90.     esac
  91.     shift
  92. done
  93.  
  94. if [ $logLevel -lt $LOGMIN ] ; then
  95.     logLevel=$LOGMIN
  96. elif [ $logLevel -gt $LOGMAX ] ; then
  97.     logLevel=$LOGMAX
  98. fi
  99.  
  100. if [ $logLevel -ne $DEFAULT_LOG_LEVEL ] ; then
  101.     echo "$appName: Log level set to $logLevel."
  102. fi
  103.  
  104. exit_or_continue(){
  105.     if [ ! "$CONTINUE" = "true" ] ; then
  106.         exit 1
  107.     fi
  108. }
  109.  
  110. #
  111. # Ensure the user is root
  112. #
  113.  
  114. USER_ID=`id | tr "\(" "=" | cut "-d=" -f2`
  115.  
  116. if [ ! $USER_ID = 0 ] ; then
  117.     echo
  118.     echo "### $appName must be run by the 'root' superuser."
  119.     echo "    Please login as root and try again."
  120.     echo
  121.     exit 2
  122. fi
  123.  
  124. #
  125. # Get a valid key file
  126. #
  127.  
  128. if [ -z "$ENL_KEYS" -o ! -r "$ENL_KEYS" ] ; then
  129.     KEY_FILE=/etc/enlighten
  130. else
  131.     KEY_FILE=$ENL_KEYS
  132. fi
  133.  
  134. if [ ! -r "$KEY_FILE" ] ; then
  135.     echo "$appName: Fatal: Could not read file $KEY_FILE." 1>&2
  136.     echo "$appName: Reinstall Enlighten on this host." 1>&2
  137.     exit 1
  138. fi
  139.  
  140. #
  141. # Setup ENLIGHTEN. 
  142. #
  143. # First try the environment variable. If that is not set properly,
  144. # override the value with $KEY_FILE's value.
  145. #
  146. # If KEY_FILE is missing, '^enlighten=' is missing from KEY_FILE,
  147. # or the directory is missing, exit.
  148. #
  149.  
  150. if [ ! -d "$ENLIGHTEN" ] ; then
  151.     ENLIGHTEN=""
  152. fi
  153.  
  154. if [ -z "$ENLIGHTEN" ] ; then 
  155.     ENLIGHTEN=`egrep "^enlighten=" $KEY_FILE | cut "-d=" -f2-`
  156.     export ENLIGHTEN
  157. fi
  158.  
  159. #
  160. # Get EMD_DIR
  161. #
  162.  
  163. EMD_DIR=`egrep "^emd_dir=" $KEY_FILE | cut "-d=" -f2-`
  164. EMD_HOST=`egrep "^emd_host=" $KEY_FILE | cut "-d=" -f2-`
  165.  
  166. if [ ! -d "$ENLIGHTEN" -a ! -d "$EMD_DIR" ] ; then 
  167.     echo "$appName: Could not find an ENLIGHTEN directory." 1>&2
  168.     echo "$appName: Please ensure the validity of $KEY_FILE, or reinstall." 1>&2
  169.     exit 1
  170. fi
  171.  
  172. #
  173. # Stop daemons if necessary
  174. #
  175.  
  176. if [ "$RESTART" = "true" ] ; then
  177.     if [ -x $ENLIGHTEN/bin/stop_enl_daemons ] ; then
  178.         $ENLIGHTEN/bin/stop_enl_daemons
  179.         if [ $? -ne 0 ] ; then
  180.             exit_or_continue
  181.         fi
  182.     else
  183.         $EMD_DIR/bin/stop_enl_daemons
  184.         if [ $? -ne 0 ] ; then
  185.             exit_or_continue
  186.         fi
  187.     fi
  188. fi
  189.  
  190. echo
  191. echo "$appName: Starting Enlighten daemons on `date`"
  192. echo
  193.  
  194. # get a list of IP addresses for this host
  195. # only type inet, not loopback, not down, not broadcast
  196. emdHostKeyIsIPaddr=0
  197. gial=
  198. if [ -x $EMD_DIR/bin/gial ] ; then
  199.     gial=$EMD_DIR/bin/gial
  200. fi
  201.  
  202. if [ ! -z "$gial" ] ; then
  203.     for ipaddr in `$gial`
  204.     do
  205.     if [ "$EMD_HOST" = "$ipaddr" ] ; then
  206.         # override the result of the uname if we match 
  207.         # on an IP address
  208.         emdHostKeyIsIPaddr=1
  209.     fi
  210.     done
  211. fi
  212.  
  213. #
  214. # Always start license daemons and EMD if this is the emd host
  215. #
  216. if [ $emdHostKeyIsIPaddr -eq 1 -o "$EMD_HOST" = "$hostname" ] ; then
  217.  
  218.     OLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "emdd " | \
  219.     egrep -v "enl_post_install|grep" \
  220.         | awk '{ print $'$PIDCOLUMN'; }'`
  221.  
  222.     if [ ! -z "$OLD_PID" ] ; then
  223.         echo "$appName: EMD is already running [pid $OLD_PID]."
  224.     else
  225.         if [ -z "$EMD_DIR" ] ; then
  226.             echo "$appName: Error: Could not find 'emd_dir' in $KEY_FILE." 1>&2
  227.             echo "$appName: Could not start EMD." 1>&2
  228.             exit_or_continue
  229.         else
  230.             if [ ! -x $EMD_DIR/bin/start_emdd ] ; then
  231.                 echo "$appName: Error: $EMD_DIR/bin/start_emdd was missing." 1>&2
  232.                 echo "$appName: Could not start EMD." 1>&2
  233.                 exit_or_continue
  234.             else
  235.                 echo
  236.                 echo "$appName: Invoking $EMD_DIR/bin/start_emdd..."
  237.                 export EMD_DIR logLevel
  238.                 su dbenl -c ". $EMD_DIR/.profile ; $EMD_DIR/bin/start_emdd -v $logLevel" 2>&1
  239.                 if [ $? -ne 0 ] ; then
  240.                     echo "$appName: Could not start EMD." 1>&2
  241.                     exit_or_continue
  242.                 fi
  243.  
  244.                 # Allow EMD to register its RPC services before PEP starts
  245.                 sleep $STARTUP_SECS
  246.             fi
  247.         fi
  248.     fi
  249. fi
  250.  
  251. #
  252. # Always start PEP is it is the pep host
  253. #
  254.  
  255. PEP_host=`cat $KEY_FILE | egrep "^pep_host=" | cut "-d=" -f2-`
  256.  
  257. if [ "$PEP_host" = "$hostname" ] ; then
  258.  
  259.     OLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "pep " | \
  260.     egrep -v "enl_post_install|grep" \
  261.         | awk '{ print $'$PIDCOLUMN'; }'`
  262.  
  263.     if [ ! -z "$OLD_PID" ] ; then
  264.         echo "$appName: PEP is already running [pid $OLD_PID]."
  265.     else
  266.  
  267.         if [ ! -x $ENLIGHTEN/bin/pep ] ; then
  268.             echo "$appName: Error: $ENLIGHTEN/bin/pep was missing." 1>&2
  269.             echo "$appName: Could not start PEP." 1>&2
  270.             exit_or_continue
  271.         fi
  272.  
  273.         echo 
  274.         echo "$appName: Invoking $ENLIGHTEN/bin/pep..."
  275.         $ENLIGHTEN/bin/pep -f $ENLIGHTEN/contrib/rules.txt -v $logLevel
  276.  
  277.         sleep $STARTUP_SECS;
  278.  
  279.         PEP_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "pep " | \
  280.         egrep -v "enl_post_install|grep" `
  281.         if [ -z "$PEP_PID" ] ; then
  282.             echo "$appName: Error: PEP did not start up." 1>&2
  283.             exit_or_continue
  284.         fi
  285.     fi
  286. fi
  287.  
  288. #
  289. # Start up renld if it was installed
  290.  
  291. if [ -x $ENLIGHTEN/bin/renld ] ; then
  292.  
  293.     OLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "renld " \
  294.     | egrep -v "enl_post_install|grep|renldc" \
  295.         | awk '{ print $'$PIDCOLUMN'; }'`
  296.  
  297.     if [ ! -z "$OLD_PID" ] ; then
  298.         echo "$appName: renld is already running [pid $OLD_PID]."
  299.     else
  300.         echo
  301.         echo "$appName: Invoking $ENLIGHTEN/bin/renld..."
  302.         $ENLIGHTEN/bin/renld -v $logLevel
  303.  
  304.         sleep $STARTUP_SECS;
  305.  
  306.         RENLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "renld " | \
  307.         egrep -v "enl_post_install|grep|renldc" `
  308.  
  309.  
  310.         if [ -z "$RENLD_PID" ] ; then
  311.             echo "$appName: renld did not start up." 1>&2
  312.             exit_or_continue
  313.         fi
  314.     fi
  315. fi
  316.  
  317. startAgentENL () {
  318.     #
  319.     # See if AgentENL is already running
  320.     #
  321.  
  322.     OLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "AgentENL " | \
  323.     egrep -v "enl_post_install|grep" \
  324.         | awk '{ print $'$PIDCOLUMN'; }'`
  325.  
  326.     if [ ! -z "$OLD_PID" ] ; then
  327.         echo "$appName: AgentENL is already running [pid $OLD_PID]."
  328.     else
  329.         
  330.         #
  331.         # Start AgentENL
  332.         #
  333.  
  334.         #
  335.         # For AIX 4.x, need to explicitly load NFS to load the kernel
  336.         # extension objects at system reboot
  337.         #
  338.  
  339.         VERS=`uname -v`
  340.         if [ $VERS = "4" -a $OS = "AIX" ] ; then
  341.             IBM_HOST=yes
  342.             if [ ! -x $ENLIGHTEN/bin/LoadChk ] ; then
  343.                 echo "$appName: Error: The application $ENLIGHTEN/bin/LoadChk" 1>&2
  344.                 echo "$appName: was missing. Please reinstall Enlighten." 1>&2
  345.                 exit_or_continue
  346.             fi
  347.             $ENLIGHTEN/bin/LoadChk;
  348.             sleep $STARTUP_SECS 
  349.         fi
  350.  
  351.         echo "$appName: Invoking $ENLIGHTEN/bin/AgentENL..."
  352.         ($ENLIGHTEN/bin/AgentENL $ENLIGHTEN/config/AgentENL.config)
  353.         sleep $STARTUP_SECS;
  354.  
  355.         AGENTENL_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "AgentENL " \
  356.             | egrep -v "enl_post_install|grep" | awk '{ print $'$PIDCOLUMN'; }'`
  357.         if [ -z "$AGENTENL_PID" ] ; then
  358.             echo "$appName: Error: AgentENL did not start up." 1>&2
  359.         fi
  360.     fi 
  361. }
  362.  
  363. start_AgentMon(){
  364.     if [ "$logLevel" = "0" ] ; then
  365.         $ENLIGHTEN/bin/AgentMon $agentmon_option 2>> $ENLIGHTEN/logs/AgentMon.err
  366.     else
  367.         $ENLIGHTEN/bin/AgentMon $agentmon_option -d $logLevel 1> /dev/null 2>> $ENLIGHTEN/logs/AgentMon.err &
  368.     fi
  369. }
  370.  
  371. #
  372. # Start up Events if it was installed
  373.  
  374. if [ -x $ENLIGHTEN/bin/AgentMon -a -x $ENLIGHTEN/bin/AgentENL ] ; then
  375.  
  376.     #
  377.     # Start AgentENL?
  378.     #
  379.  
  380.     configFile=$ENLIGHTEN/config/AgentENL.config
  381.  
  382.     if [ -f $configFile ] ; then
  383.     if [ -z "`egrep '^MANAGER' $configFile | grep '(disabled)'`" -a \
  384.         -z "`egrep '^COMMUNITY' $configFile | grep '(disabled)'`"  ] ; then
  385.             
  386.         startAgentENL
  387.     else
  388.         echo "$appName: (ENlighten/SNMP functionality is currently disabled.)"
  389.         if [ "$OS" = "SCO_SV" -o "$OS" = "AIX" ] ; then
  390.             agentmon_option="-s"
  391.         fi
  392.     fi
  393.     fi
  394.  
  395.     #
  396.     # See if AgentMon is licensed
  397.     #
  398.     LM_LICENSE_FILE="@$EMD_HOST" $ENLIGHTEN/bin/alc
  399.     status=$?
  400.  
  401.     if [ $status = 0 ] ; then
  402.  
  403.     #
  404.     # See if AgentMon is already running
  405.     #
  406.  
  407.     OLD_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "AgentMon " | \
  408.     egrep -v "enl_post_install|grep" \
  409.         | awk '{ print $'$PIDCOLUMN'; }'`
  410.  
  411.     if [ ! -z "$OLD_PID" ] ; then
  412.         echo "$appName: AgentMon is already running [pid $OLD_PID]."
  413.     else
  414.         
  415.         #
  416.         # Start AgentMon
  417.         #
  418.  
  419.         echo
  420.         echo "$appName: Invoking $ENLIGHTEN/bin/AgentMon..."
  421.         start_AgentMon
  422.  
  423.         sleep $STARTUP_SECS;
  424.  
  425.         #
  426.         # Make sure the port is set up with AgentENL before AgentMon starts
  427.         #
  428.  
  429.         sleep $STARTUP_SECS;
  430.  
  431.         AGENTMON_PID=`ps $OPTS | awk '{print $0, " 0"}'|grep "AgentMon " \
  432.             | egrep -v "enl_post_install|grep" | awk '{ print $'$PIDCOLUMN'; }'`
  433.  
  434.         if [ -z "$AGENTMON_PID" ] ; then
  435.         echo "$appName: Error: AgentMon did not start up." 1>&2
  436.         exit_or_continue
  437.         fi
  438.     fi
  439.     fi
  440. fi
  441.  
  442. echo
  443. echo "$appName: Enlighten daemons are active on $hostname."
  444. exit 0
  445.  
  446.